<?php
class settingService extends commonService{
    
    public function __construct(){
        parent::__construct();
		
    }
    public function t(){
        return array('setting');
    }	
	//更新文件
	public function update(){
		$query="select `varname`,`varvalue` from `{$this->t[0]}` order by `id` asc";
		$info=$this->m->mselect($query);
		$info=is_array($info)?$info:array();
		$data=array();
		foreach($info as $k=>$v){
			$data[$v['varname']]=$v['varvalue'];
		}
		$data = '<?php return ' . var_export($data,true) . ';';
		return file_put_contents(ROOT.'config/ext.inc.php',$data);
	}
    public function add_($post){
		
        $result=array();
		
        $vali=validate::check('setting',$post,'add');
        if($vali){
            $result[0]=$this->model->_i($this->t[0],$post);
        }else{
            $result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
        }
        return $result;
    }
    public function mod($id){
        $data=$this->model->_f($this->t[0],'*',$id);
		return $data;
    }
	
    public function mod_($post,$id){
        $result=array();
        
        $vali=validate::check('setting',$post,'mod',array('id::!='=>$id));
        if($vali){
    		$result[0]=$this->model->_u($this->t[0],$post,$id);
    	}else{
    		$result[0]=false;
            $result[1]="\\n".implode("\\n",validate::getMsg());
    	}
        return $result;
    }
    public function del($id){
        $return=array();
		$return[0]=$this->model->_d($this->t[0],$id);
        return $return;
    }
    public function li($condition=array(),$extra='',$extra_data=array()){
        $return=array();
        $query="select * from `{$this->t[0]}` where 1 {$extra} order by `id` asc";
        $p=new smart_pager(array($query,$extra_data),$this->m,50);
        //$p->address('&block_id=%block_id%','block_id',$condition['block_id']);
		foreach($condition as $k=>$v){
			$p->address("&{$k}=%{$k}%",$k,$v);
		}
        if($p->total_num>0){
            $return[]=$this->m->mselect($p->query,$extra_data);
            $return[]=$p;
        }
        return $return;
    }
//
}